import sys

import numpy as np
import os

from PIL import Image
from keras.engine.saving import load_model

from photoClassify.project.faceClasiify.faceDataLoad import loadFaceData

# 手动测试模型准确率
if __name__ == '__main__':
    model = load_model('saved_models/武林外传.h5')

    (num_classes, x_train, y_train) = loadFaceData()  # 验证吗图片数据
    scores = model.evaluate(x_train, y_train, verbose=1)
    print('Test loss:', scores[0])
    print('Test accuracy:', scores[1])
    sys.exit(1)

    # path = "/Users/mc/Desktop/TF/武林外传/白展堂"  # 要训练的人脸文件夹 每人一个 文件夹名就是人名
    # peoplesDir = sorted(os.listdir(path))
    # peoplesDir.remove(".DS_Store")  # 删除mac文件夹下的隐藏文件
    # peopleSize = len(peoplesDir)
    #
    # x_train = []
    # y_train = []
    # classNum = 0
    # for picItem in peoplesDir:
    #     picPath = os.path.abspath(os.path.join(path, picItem))
    #     if picPath.endswith('.jpg') | picPath.endswith('.png'):
    #         image = Image.open(picPath).resize((76, 76))
    #         x_train.append(np.asarray(image))
    #         y_train.append(np.asarray([classNum]))
    # classNum = classNum + 1
    # x_train = np.asarray(x_train)
    # y_train = np.asarray(y_train)
    # # Normalize data.
    # x_train = x_train.astype('float32') / 255
    # faceID = model.predict(x_train)
    # if faceID.shape[-1] > 1:
    #     result = faceID.argmax(axis=-1)
    # else:
    #     result = (faceID > 0.5).astype('int32')
    # print(result)
